define(function (require,exports,module) {
    var myPub=require('./public');
    var oWindow=$(window);
    var orderOptionBtn=$('.js_orderOptionBtn');
    var oBossInfo = $('.js_bossInfo');              //商家信息 js_bossInfo
    var oBossName = $('.js_bossName');              //店家名字
    var resizeTimer = null;

    var imgUrl = $('.js_lazyImg').attr('src');

    module.exports={
        init:function () {
            orderDetail.orderDetInit(true);
            orderDetail.gitfOrderTimer($(".js_giftOrderTimer"));
            oWindow.on('resize',function () {
                if(resizeTimer){
                    clearTimeout(resizeTimer);
                }
                resizeTimer=setTimeout(function () {
                    orderDetail.orderDetInit(true)
                })
            })
        }
    }

    var orderDetail={
        orderDetInit:function (bOff) {
            orderDetail.btnAskLayer();
        },
        btnAskLayer:function () {
        //    底部的点击事件绑定给底部的大盒子
        //     console.log(oFootBtn);
            orderOptionBtn.hammer().on('tap',function (e) {
                var _btnA=$(e.gesture.target);
                var _typeNum=_btnA.attr('_type');
                var orderSn = '';

                if(_typeNum!==undefined){
                    myPub.HamstopPropaga();
                }
            	var oId = _btnA.attr("oId");

                switch (_typeNum * 1) {
                    // 0 删除订单
                    case 0:
                        myPub.askLayer('确认要删除订单吗？ ', function () {
                            //    确认的回调
                            G_JSON_GET('/member/order/delete', {"orderId": oId}, function (data) {
                                if (data.status == "success") {
                                    location.reload();
                                } else {
                                    myPub.TipLayer(data.message);
                                }
                            });
                            myPub.LayerCloseAll();
                        }, function () {
                            //    取消的回调
                        }, null, function () {
                            //    callback
                        });
                        break;
                    // 1 提醒发货
                    case 1:
                        var styleTitle = "提醒发货成功!请耐心等候";
                        var remindStyle = "background-color:rgba(0,0,0,0.5); color:#fff; border:none; border-radius: 5px; min-width:50%"
                        myPub.TipLayer(styleTitle, remindStyle);
                        break;
                    // 2.查看物流
                    case 2:
                        //跳转到查看物流页面
                        window.location.href = "/h/goodsafter/expressDetail/" + orderSn;
                        break;
                    // 3 确认收货
                    case 3:
                        myPub.askLayer('确认要收货吗？ ', function () {
                            //    确认的回调
                            G_JSON_GET('/member/order/receive', {"orderId": oId}, function (data) {
                                if (data.status == "success") {
                                    //location.reload();
                                    // window.location.href = '/shop/goodsComment/comment/'+oId;
                                    window.location.href= "/h/goodsafter/applyAppraisal/" + oId + '?picImgUrl=' + imgUrl;
                                } else {
                                    myPub.TipLayer(data.message);
                                }
                            });
                            myPub.LayerCloseAll();
                        }, function () {
                            //    取消的回调
                        }, null, function () {
                            //    callback
                        });
                        break;
                    // 4 评价晒单
                    case 4:
                         G_JSON_GET('/shop/goodsComment/find_comment/'+oId+'?receiveDate='+_btnA.attr('receiveDate'), null, function (data) {
                             if (data.status == "first") {
                                 // window.location.href= "/shop/goodsComment/comment/"+oId;
                                 window.location.href= "/h/goodsafter/applyAppraisal/" + oId + '?picImgUrl=' + imgUrl;
                             }else if (data.status == "append") {
                                 window.location.href= "/shop/goodsComment/appendComment/"+oId;
                             } else {
                                 myPub.TipLayer(data.message);
                             }
                         });
                        break;
                    // 5 去支付
                    case 5:
                        var payUrl = "/shop/payment/continuePay";
                        var data = {paymentId:oId};
                        payPub.submitPay(payUrl,data);
                        break;
                    // 6 取消订单
                    case 6:
                        myPub.askLayer('确认要取消订单吗？ ', function () {
                            G_JSON_POST('/shop/payment/cancelNoPayOrder', {paymentId:oId}, function (data) {
                                if (data.status == "success") {
                                    location.reload();
                                } else {
                                    myPub.TipLayer(data.message);
                                }
                            });
                            myPub.LayerCloseAll();
                        }, function () {
                            //    取消的回调
                        }, null, function () {
                            //    callback
                        });
                        break;
                    // 7 分享给TA
                    case 7:
                        window.location.href = "/shop/gift/sharePage/" + oId;
                        break;
                    default:
                        break;
                }
            })
        },
        cancleCauseHtml:function () {
            var shtml='';
            shtml='<div class="cancleOrderCause js_cancleOrderCause">'+
                    '<div class="cancleReason backWhite">'+
                        '<div class="cancleTit borBEA">'+
                            '<h6>请选择取消原因</h6>'+
                        '</div>'+
                        '<div class="cancleRealReason">'+
                            '<div class="selectReason js_selectReason">'+
                                '<p class="Bflex1">不想买了</p>'+
                                '<p class="Bflex1">拍错/拍多/地址错误</p>'+
                                '<p class="Bflex1">商家缺货</p>'+
                                '<p class="Bflex1">买错了</p>'+
                                '<p class="Bflex1">其他</p>'+
                            '</div>'+
                            '<div class="writeReason">'+
                                '<textarea name="" id="" cols="30" rows="9" placeholder="具体原因（选填）"></textarea>'+
                            '</div>'+
                        '</div>'+
                    '</div>'+
                '</div>';
            return shtml;
        },
        causeChangeColor:function () {
            $('.js_selectReason p').on('click',function () {
                var index=$('.js_selectReason p').index($(this));
                // console.log(index);
                $('.js_selectReason p').removeClass('active').eq(index).addClass('active');
            })
        },
        // 复制操作
        oCopy: function(obj) {
            obj.select();
            document.execCommand("Copy");
            myPub.TipLayer("复制成功!");
        },
        gitfOrderTimer: function (timerBox) {
            var _this = this;
            var timerSecond = parseInt(timerBox.attr("data-timer"));
            var timerText = _this.formatTimer(timerSecond);
            timerBox.text(timerText);
            var tempTimerInterval = setInterval(function () {
                timerSecond -- ;
                var timerText = _this.formatTimer(timerSecond);
                timerBox.text(timerText);
                if(timerSecond <= 0){
                    clearInterval(tempTimerInterval);
                }
            },1000);
        },
        formatTimer:function (timerSecond) {
            var second =  timerSecond%60;
            var min = ((timerSecond - timerSecond%60)/60)%60;
            var honr = (timerSecond - timerSecond%3600)/3600;
            if(honr < 10){
                honr = "0" + honr;
            }
            if(min < 10){
                min = "0" + min;
            }
            if(second < 10){
                second = "0" + second;
            }
            var timerText = honr + ":" + min + ":" + second;
            return timerText;
        }
    }
})